﻿// ....................................................................................................................
//	Author: Copyright (C) 2012 Ing. Marek Hubal
//	Email: hubal@acasoftware.org
// ....................................................................................................................

using System;

namespace core
{
    /// <summary>Trieda IControl</summary>
	public class IControl : System.Windows.Forms.Control
	{
        /// <summary>Umiestnenie prvku dovnutra rodica</summary>
        /// <param name="pControl">prvok</param>
        /// <param name="pParent">rodic</param>
        /// <param name="pLeft">pozicia zlava</param>
        /// <param name="pTop">pozicia zhora</param>
        /// <param name="pRight">pozicia zprava</param>
        /// <param name="pBottom">pozicia zdola</param>
        public static void PlaceControl_Inside(System.Windows.Forms.Control pControl, System.Windows.Forms.Control pParent, int pLeft, int pTop, int pRight, int pBottom)
        {
            System.Drawing.Size CS = pParent.ClientSize;
            pControl.SetBounds(pLeft, pTop, CS.Width - pLeft - pRight, CS.Height - pTop - pBottom);
        }
        /// <summary>Umiestnenie prvku dovnutra rodica</summary>
        /// <param name="pControl">prvok</param>
        /// <param name="pParent">rodic</param>
        /// <param name="pLeft">pozicia zlava</param>
        /// <param name="pTop">pozicia zhora</param>
        public static void PlaceControl_Inside_LeftTop_LeftTop(System.Windows.Forms.Control pControl, System.Windows.Forms.Control pParent, int pLeft, int pTop, int pWidth = -1, int pHeight = -1)
        {
            System.Drawing.Size CS = pControl.Size;
            pControl.SetBounds(pLeft, pTop, pWidth == -1 ? CS.Width : pWidth, pHeight == -1 ? CS.Height : pHeight);
        }
        /// <summary>Umiestnenie prvku dovnutra rodica</summary>
        /// <param name="pControl">prvok</param>
        /// <param name="pParent">rodic</param>
        /// <param name="pLeft">pozicia zlava</param>
        /// <param name="pTop">pozicia zhora</param>
        public static void PlaceControl_Inside_RightBottom_RightBottom(System.Windows.Forms.Control pControl, System.Windows.Forms.Control pParent, int pRight, int pBottom, int pWidth = -1, int pHeight = -1)
        {
            System.Drawing.Size CS = pParent.Size;
            if (pWidth != -1) pControl.Width = pWidth;
            if (pHeight != -1) pControl.Height = pHeight;
            pControl.Left = CS.Width - pRight - pControl.Width;
            pControl.Top = CS.Height - pBottom - pControl.Height;
        }

        /// <summary>Umiestnenie prvku zvonku rodica - LeftTop voci LeftBottom</summary>
        /// <param name="pControl">prvok</param>
        /// <param name="pParent">rodic</param>
        /// <param name="pLeft">pozicia zlava</param>
        /// <param name="pBottom">pozicia zdola</param>
        public static void PlaceControl_Outside_LeftTop_LeftBottom(System.Windows.Forms.Control pControl, System.Windows.Forms.Control pParent, int pLeft, int pBottom, int pWidth = -1, int pHeight = -1)
        {
            pControl.SetBounds(pParent.Left + pLeft, pParent.Bottom + pBottom, pWidth == -1 ? pControl.Width : pWidth, pHeight == -1 ? pControl.Height : pHeight);
        }
        /// <summary>Umiestnenie prvku zvonku rodica - LeftTop voci LeftBottom</summary>
        /// <param name="pControl">prvok</param>
        /// <param name="pParent">rodic</param>
        /// <param name="pRight">pozicia zprava</param>
        /// <param name="pBottom">pozicia zdola</param>
        public static void PlaceControl_Outside_TopRight_RightBottom(System.Windows.Forms.Control pControl, System.Windows.Forms.Control pParent, int pRight, int pBottom, int pWidth = -1, int pHeight = -1)
        {
            System.Drawing.Size CS = pControl.Size;
            pControl.SetBounds(pParent.Right - pRight - CS.Width, pParent.Bottom + pBottom, pWidth == -1 ? CS.Width : pWidth, pHeight == -1 ? CS.Height : pHeight);
        }
        /// <summary>Umiestnenie prvku zvonku rodica - LeftTop voci LeftBottom</summary>
        /// <param name="pControl">prvok</param>
        /// <param name="pParent">rodic</param>
        /// <param name="pRight">pozicia zprava</param>
        /// <param name="pBottom">pozicia zdola</param>
        public static void PlaceControl_Outside_TopRight_LeftTop(System.Windows.Forms.Control pControl, System.Windows.Forms.Control pParent, int pTop, int pRight)
        {
            System.Drawing.Size CS = pControl.Size;
            pControl.SetBounds(pParent.Left - pRight - CS.Width, pParent.Top + pTop, CS.Width, CS.Height);
        }
        /// <summary>Umiestnenie prvku zvonku rodica - LeftTop voci LeftBottom</summary>
        /// <param name="pControl">prvok</param>
        /// <param name="pParent">rodic</param>
        /// <param name="pTop">pozicia zhora</param>
        /// <param name="pRight">pozicia zprava</param>
        public static void PlaceControl_Outside_LeftTop_TopRight(System.Windows.Forms.Control pControl, System.Windows.Forms.Control pParent, int pTop, int pRight, int pWidth = -1, int pHeight = -1)
        {
            pControl.SetBounds(pParent.Right + pRight, pParent.Top + pTop, pWidth == -1 ? pControl.Width : pWidth, pHeight == -1 ? pControl.Height : pHeight);
        }
        /// <summary>Umiestnenie prvku zvonku rodica - LeftTop voci LeftBottom</summary>
        /// <param name="pControl">prvok</param>
        /// <param name="pParent">rodic</param>
        /// <param name="pLeft">pozicia zlava</param>
        /// <param name="pBottom">pozicia zdola</param>
        public static void PlaceControl_Outside_LeftTop_LeftTop(System.Windows.Forms.Control pControl, System.Windows.Forms.Control pParent, int pLeft, int pTop, int pWidth = -1, int pHeight = -1)
        {
            pControl.SetBounds(pParent.Left + pLeft, pParent.Top + pTop, pWidth == -1 ? pControl.Width : pWidth, pHeight == -1 ? pControl.Height : pHeight);
        }
        /// <summary>Umiestnenie prvku zvonku rodica - TopRight voci TopRight</summary>
        /// <param name="pControl">prvok</param>
        /// <param name="pParent">rodic</param>
        /// <param name="pRight">pozicia zprava</param>
        /// <param name="pTop">pozicia zdola</param>
        public static void PlaceControl_Outside_TopRight_TopRight(System.Windows.Forms.Control pControl, System.Windows.Forms.Control pParent, int pRight, int pTop, int pWidth = -1, int pHeight = -1)
        {
            System.Drawing.Size CS = pControl.Size;
            pControl.SetBounds(pParent.Right - pRight - CS.Width, pParent.Top - CS.Height - pTop, pWidth == -1 ? CS.Width : pWidth, pHeight == -1 ? CS.Height : pHeight);
        }

        /// <summary>Nastavenie automatickej hlby podla zadaneho prvku</summary>
        /// <param name="pControl">prvok, ktoremu nastavujem hlbku</param>
        /// <param name="pLastControl">prvok</param>
        /// <param name="pDistance">vzdialenost</param>
        public static void SetAutoHeight(System.Windows.Forms.Control pControl, System.Windows.Forms.Control pLastControl, int pDistance = 20)
        {
            pControl.Height -= pControl.ClientSize.Height - pLastControl.Bottom - pDistance;
        }

        /// <summary>Nastavenie poradia tabstop</summary>
        /// <param name="pControls">pole controls</param>
        public static void SetTabOrder(System.Windows.Forms.Control[] pControls)
        {
            for (int i = 0; i < pControls.Length; i++)
            {
                pControls[i].TabIndex = i;
                pControls[i].TabStop = true;
            }
        }

    }
}
